package validator

import (
	"github.com/pkg/errors"
	"github.com/zeromicro/go-zero/rest/httpx"
	"gopkg.in/go-playground/validator.v9"
	"net/http"
)

func DefaultGetValidParams(r *http.Request, params interface{}) error {
	if err := httpx.ParsePath(r, params); err != nil {
		return err
	}
	//绑定表单
	_ = httpx.ParseForm(r, params);
	//获取验证器,获取翻译器
	err := validGlobal.Struct(params)
	if err != nil {
		errs := err.(validator.ValidationErrors)
		//sliceErrs := []string{}
		for _, e := range errs {
			return errors.New(e.Translate(transGlobal))
			//sliceErrs = append(sliceErrs, e.Translate(transGlobal))
		}
		//return errors.New(strings.Join(sliceErrs, ","))
	}
	return nil
}

